<?php

class Admin_PagesController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
    	$pages = new Application_Model_DbTable_Pages( );
       	$this->view->pages = $pages->fetchAll();
    }

    public function editAction()
    {
    	$id = (int)$this->_request->getParam( 'id' );
    	$this->view->pageTitle = ($id) ? 'עריכת דף' : 'הוספת דף';
    	$formParams = array(
    		'legendLabel' => $this->view->pageTitle 
    	);
        $this->view->form = new Admin_Form_Page( $formParams );
        if($id){
        	$_page = new Application_Model_DbTable_Pages( );
        	$pageDetails = $_page->find( $id )->current( )->toArray( );
        	$this->view->form->setDefaults($pageDetails);	
        }
      	if($this->_request->isPost( )){
        	if($this->view->form->isValid( $this->_request->getPost( ))){
        		$_model = new Admin_Model_Page();
        		$_model->save( $this->view->form->getValues( ) );
        		$this->_forward('index');		
        	}
        }
       
	
				
    }
    public function deleteAction()
		{
				if ($this->getRequest()->isPost()) {
				$del = $this->getRequest()->getPost('del');
				
				$id = $this->getRequest()->getPost('id');
				$_page = new Application_Model_DbTable_Pages( );
				$_page->remove($id);
				
				
		}
}
		}

